<?php


namespace App\Services\Algo;

use App\Interf\Calculable;
use TestingItemService;
use App\Models\LogHelper;

class JointDexterityTestingAlgo extends BaseTestingAlgo implements Calculable
{
    public $allAnswers ;
    private $typeFourExpress ;
    public function __construct($tid, $answerStr, $typeFourExpress = null)
    {
        parent::__construct($tid, $answerStr);
        $this->typeFourExpress = $typeFourExpress;
        $this->allAnswers = $this->convertAllAnswers();

    }

    public function calculate()
    {

        return $this->entrance($this->tid, $this->answers);

    }

    /**
     * 将拼装后的答案转换成字符串
     * @return string
     */
  public function resultToStr(){
        return $this->arrToStr($this->answers);
    }




    /**
     * @param $tid
     * @param $answers
     * @return float|null
     */
    protected function entrance($tid,$answers){

        $answer7= $this->getAnswerObjByIndex(7);

        $totalScore =$answer7['weight'];
        return $totalScore;
    }


    protected function convertAllAnswers(){
        LogHelper::log('before calculate BMI=============>');
        LogHelper::log($this->answers);
        $TotalScore = [];
        LogHelper::log('this->typeFourExpress=============>');
        LogHelper::log($this->typeFourExpress);
        if($this->typeFourExpress){
            foreach ($this->typeFourExpress as $d){
                if($d['index'] == 7){
                    array_push($TotalScore,$d);
                    break;
                }
            }

            $result = $this->fourTypeArray($TotalScore,$this->answers);

            foreach($result as $v){
                array_push($this->answers,$v);
            }
        }

    }








}